package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.pojo.SkuInfo;
import com.atguigu.gmall.product.service.SkuInfoService;
import com.atguigu.gmall.product.vo.SkuInfoVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product")
public class SkuController {
    @Autowired
    SkuInfoService skuInfoService;

    // http://api.gmall.com/admin/product/saveSkuInfo

    @GetMapping("/onSale/{skuId}")
    public Result up(@PathVariable Long skuId){
        skuInfoService.upGoods(skuId);
        return Result.ok();
    }

    @GetMapping("/cancelSale/{skuId}")
    public Result down(@PathVariable Long skuId){
        skuInfoService.downGoods(skuId);
        return Result.ok();
    }

    /**
     * 添加Sku属性
     * @param skuInfoVo
     * @return
     */
    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfoVo skuInfoVo){
        skuInfoService.saveSkuInfo(skuInfoVo);
        return Result.ok();
    }

    //http://api.gmall.com/admin/product/list/1/10
    @GetMapping("/list/{pn}/{ps}")
    public Result getSkuList(@PathVariable Long pn, @PathVariable Long ps){
        Page<SkuInfo> page = skuInfoService.page(new Page<>(pn, ps));
        return Result.ok(page);
    }

}
